﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
using Models.APIModels;
using Models.ServerModels;
using DdnsServer.DnspodAPI;

namespace Manage
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ApiConfigModel cfg = new ApiConfigModel
            {
                ApiId = "94107",
                ApiToken = "01623d077c1ec1fe9620a3ed7b8dc6dd",
                ErrorOnEmpty = "no",
                Format = "json",
                Lang = "cn",
                ServerAddress = "https://dnsapi.cn",
                UserAgent = "LNDDNS/v 0.3 beta (lovesans@gmail.com)",
                UserId = ""
            };
            DomainApi da = new DomainApi(cfg);
            var lst = da.GetDomainList();
            for (int i = 0; i < lst.domains.Count; i++)
            {
                var item = lst.domains[i];
                
                    tbx.AppendText("域名：" + item.name + Environment.NewLine);
                    tbx.AppendText("域名ID:" + item.id + Environment.NewLine);
                    tbx.AppendText("记录:" + Environment.NewLine);
                    RecordApi ra = new RecordApi(cfg);
                    var rec = ra.GetRecordList(item.id);
                    for (int j = 0; j < rec.records.Count; j++)
                    {
                        var r = rec.records[j];
                        tbx.AppendText("  record_id:" + r.id + Environment.NewLine);
                        tbx.AppendText("  record_line:" + r.line + Environment.NewLine);
                        tbx.AppendText("  record_line_id:" + r.line_id + Environment.NewLine);
                        tbx.AppendText("  record_name:" + r.name + Environment.NewLine);
                        tbx.AppendText("  type:" + r.type + Environment.NewLine);
                        tbx.AppendText("  value:" + r.value + Environment.NewLine);
                    }
            }
        }
    }
}
